package models

import (
	"awesome/config"
	"gorm.io/gorm"
)

type Group struct {
	gorm.Model
	Name   string `json:"name" gorm:"not null"`
	Desc   string `json:"desc"`
	Status string `json:"status" gorm:"default: 0"`
	Pid    string `json:"pid" gorm:"default: 0"`
}

func CreateGroup(group *Group) error {
	return config.DB.Create(group).Error
}

func GetGroupByID(id uint) (*Group, error) {
	var group Group
	err := config.DB.First(&group, id).Error
	if err != nil {
		return nil, err
	}
	return &group, nil
}

func GetGroupList(sizeInt int, offset int) (*[]Group, error) {
	var groups []Group
	err := config.DB.Model(&Group{}).Limit(sizeInt).Offset(offset).Find(&groups).Error
	if err != nil {
		return nil, err
	}
	return &groups, nil
}
